package com.spsoft.system.service.impl;

import com.spsoft.core.constants.CacheConstant;
import com.spsoft.core.enums.ResponseEnum;
import com.spsoft.core.model.Result;
import com.spsoft.system.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class CacheUpdateServicelmpl implements CacheUpdateService {
    /**
     * 数据字典
     */
    private final DefBizdictService defBizdictService;
    /**
     * 功能菜单
     */
    private final SysFunlistService sysFunlistService;
    /**
     * 系统参数
     */
    private final BiDataConfigInfoService biDataConfigInfoService;
    /**
     * 根据缓存代码更新缓存
     *
     * @param cacheCode 高速缓存代码
     * @return {@link Result}
     */
    @Override
    public Result updateCache(String cacheCode) {
        log.info("更新缓存开始，缓存代码：{}", cacheCode);
        switch (cacheCode){
            case CacheConstant.SYS_CACHE_APP_PARAM:
                biDataConfigInfoService.upadteBiDataConfigInfoToCache();
                log.info("更新缓存开始，缓存代码：{}", cacheCode);
                return Result.OK();
            case CacheConstant.SYS_CACHE_DICT:
                defBizdictService.updateDictCache();
                log.info("更新缓存开始，缓存代码：{}", cacheCode);
                return Result.OK();
            case CacheConstant.SYS_CACHE_MENU_AUTH:
                sysFunlistService.updateAllMenuAuthToCache();
                log.info("更新缓存开始，缓存代码：{}", cacheCode);
                return Result.OK();
            default:
                return Result.ERROR(ResponseEnum.CACHE_ERROR);
        }


    }
}
